﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using SqlData = System.Data.SqlClient.SqlDataAdapter;

namespace DAL
{
    public class DBHelper
    {
        //SQL Server profiler
        public static string connstr = "server=.;uid=sa;pwd=123456;database=king";

        public static DataTable ExcuteTable(string sql, params SqlParameter[] sqlParameters)
        {
            using (SqlData sda = new SqlData(sql, connstr))
            {
                if (sqlParameters != null && sqlParameters.Count() > 0)
                    sda.SelectCommand.Parameters.AddRange(sqlParameters);
                using (DataTable table = new DataTable())
                {
                    sda.Fill(table);
                    return table;
                }
            }
        }
        public static int ExecuteNonQuery(string sql, params SqlParameter[] sqlParameters)
        {
            using (SqlConnection conn = new SqlConnection(connstr))
            {

                using (SqlCommand comm = new SqlCommand(sql, conn))
                {
                    if (sqlParameters != null && sqlParameters.Count() > 0)
                        comm.Parameters.AddRange(sqlParameters);
                    conn.Open();
                    return comm.ExecuteNonQuery();
                }
            }
        }
    }
}
